import { MenuService } from './menu.service';
import { SysRoleEntity } from './../../entity/sys-role.entity';
import { AuthService } from './../auth/auth.service';
import { CommonRepService } from './../../common/services/commonRep.service';
import { Injectable, forwardRef, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

@Injectable()
export class RoleService extends CommonRepService<SysRoleEntity>{
    constructor(
        @InjectRepository(SysRoleEntity) private readonly sysRoleServ: Repository<SysRoleEntity>,
        private readonly menuServ: MenuService
    ) {
        super(sysRoleServ);
    }

    async queryRoleMenuId(roleId: string): Promise<any> {
        const menuIds = await this.sysRoleServ.query(`
            SELECT sp.id
            FROM (
                SELECT * 
                FROM sys_role_permission 
                WHERE sys_role_permission.roleId = ${roleId}
            ) srp
            LEFT JOIN sys_permission sp on sp.id = srp.premissionId
        `);
        return { list: menuIds };
    }

}
